package com.nl.strings;

import java.util.Arrays;

public class MergeSortArray {
	
	/**
	 * 两个有序数组合并，数组1有足够空间容纳数组二
	 * @param arrMax
	 * @param len1
	 * @param arrMin
	 * @param len2
	 * @return
	 */
	static int[] merge(int[] arrMax,int len1,int[] arrMin,int len2){
		int indexMax = len1-1;
		int indexMin = len2-1;
		int index = len1+len2-1;
		while(indexMax>=0 && indexMin>=0){
			int tmp;
			if(arrMax[indexMax]<arrMin[indexMin]){
				tmp = arrMax[indexMax--];
			}else{
				tmp = arrMin[indexMin--];
			}
			arrMax[index--]=tmp;
		}

		while(indexMin>=0){
			arrMax[index--] =arrMin[indexMin--];
		}

		return arrMax;
	}
	
	public static void main(String[] args) {

		int[] arrMax=new int[]{1000,500,54,12,3,0,0,0,0,0,0};
		int[] arrMin = new int[]{2222,22,2};
		System.out.println(Arrays.toString(merge(arrMax,5,arrMin,3)));

	}

}
